function getDirection(x,y){
	if(x>y){
		return 'horizontal';
	}
	if(y>x){
		return 'vertical';
	}
	return '';
}
const MIN_SWIPE_DISTANCE=20;
const MIN_HOLD_TIME=600;
const MAX_SWIPE_TIME=200;
export default{
	data(){
		return {
			touchDirection:'',// horizontal,vertical
			touchType:''// swipe,pan,hold
		};
	},
	methods:{
		$_bear_touchStart(event){
			this.$_bear_resetTouchStatus();
			this.startX=event.touches[0].clientX;
			this.startY=event.touches[0].clientY;
			this.startTime=Date.now();
		},
		$_bear_touchMove(event){
			const touch=event.touches[0];
			this.deltaX=touch.clientX-this.startX;
			this.deltaY=touch.clientY-this.startY;
			this.offsetX=Math.abs(this.deltaX);
			this.offsetY=Math.abs(this.deltaY);
			this.touchDuration=Date.now()-this.startTime;
			this.touchDirection=this.touchDirection||getDirection(this.offsetX,this.offsetY);
			if(this.offsetX||this.offsetY){
				this.touchType='pan';
			}
			if(!this.touchType&&this.touchDuration>MIN_HOLD_TIME){
				this.touchType='hold';
			}else if(
				this.touchDuration<MAX_SWIPE_TIME&&
				(this.offsetX>MIN_SWIPE_DISTANCE||this.offsetY>MIN_SWIPE_DISTANCE)
			){
				this.touchType='swipe';
			}
		},
		$_bear_resetTouchStatus(){
			this.touchDirection='';
			this.touchType='';
			this.deltaX=0;
			this.deltaY=0;
			this.offsetX=0;
			this.offsetY=0;
		}
	}
};
